// 异步代码使用Promise改进
// 方法1
let p1 = new Promise((resolve, reject) => {
  setTimeout(() => {
    let a = "hello";
    resolve(a);
  }, 10);
});

let p2 = new Promise((resolve, reject) => {
  setTimeout(() => {
    let b = "lagou,";
    resolve(b);
  }, 10);
});

let p3 = new Promise((resolve, reject) => {
  setTimeout(() => {
    let c = "I love U";
    resolve(c);
  }, 10);
});

Promise.all([p1, p2, p3]).then((arr) => {
  const result = arr.join(" ");
  console.log(result);
});

// 方法2
let p = new Promise((resolve, reject) => {
  setTimeout(() => {
    let a = "hello ";
    resolve(a);
  }, 10);
});

p.then((value) => {
  return new Promise((resolve) => {
    setTimeout(() => {
      let b = "lagou,";
      resolve(value + b);
    }, 10);
  });
}).then((value) => {
  setTimeout(() => {
    let c = " I love U";
    const result = value + c;
    console.log(result);
  }, 10);
});
